<template>
  <div>
    <!--    <el-button @click="appear">出现</el-button>-->

    <el-form
      ref="searchForm"
      class="searchForm"
      :model="searchForm"
      label-width="auto"
    >
      <el-row :gutter="18">
        <!--        合计24份  -->
        <el-col :span="6">
          <el-form-item prop="queryCondition.nickNameSml" label="姓名">
            <el-input v-model.trim="searchForm.queryCondition.nickNameSml">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="queryCondition.playerCodeSml" label="编号">
            <el-input v-model.trim="searchForm.queryCondition.playerCodeSml">
            </el-input>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item prop="queryCondition.goldCoinMin" label="最小值">
            <el-input v-model.number="searchForm.queryCondition.goldCoinMin">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item prop="queryCondition.goldCoinMax" label="最大值">
            <el-input v-model.number="searchForm.queryCondition.goldCoinMax">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="18">
        <el-col :span="12">
          <el-form-item label="职业" prop="queryCondition.professions">
            <el-checkbox-group v-model="searchForm.queryCondition.professions">
              <!--            <el-checkbox label="writer">作家</el-checkbox>-->
              <!--            <el-checkbox label="architect">建筑师</el-checkbox>-->
              <!--            <el-checkbox label="wizard">巫师</el-checkbox>-->
              <el-checkbox
                v-for="e in professionTypes"
                :key="e.index"
                :label="e.value"
                >{{ e.text }}</el-checkbox
              >
            </el-checkbox-group>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-edit"
          @click="queryByCondition(1)"
          >查询</el-button
        >
        <el-button
          type="warning"
          icon="el-icon-remove"
          @click="() => $refs.searchForm.resetFields()"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!--     {
      "playerId": 170,
      "playerCode": "8110727",
      "nickname": "黄楷文",
      "goldCoin": 58,
      "silverCoin": 85,
      "profession": "writer",
      "usernameFk": "2016207210",
      "version": 0
    }, -->
    <!--    父标签 与 子标签-->
    <!--    调用端 与 被调用端-->
    <!--    父组件 与 子组件-->

    <el-row :gutter="12">
      <el-col :span="2">
        <insert-player @postSubmit="queryByCondition"></insert-player>
      </el-col>
      <el-col :span="20">
        <gold-coin-deal
          :supplier="supplier"
          :consumer="consumer"
          @postSubmit="queryByCondition"
        ></gold-coin-deal>
      </el-col>
    </el-row>
    <!--    new InsertPlayer(title,abc)-->
    <el-table :data="results" class="resultsTable" stripe height="300px">
      <el-table-column prop="playerCode" label="编号"></el-table-column>
      <el-table-column prop="nickname" label="昵称"></el-table-column>
      <el-table-column prop="goldCoin" label="金币数量"></el-table-column>
      <el-table-column prop="silverCoin" label="银币数量"></el-table-column>
      <el-table-column
        label="职业"
        :formatter="professionFormat"
      ></el-table-column>

      <!--              <el-table-column label="职业" :formatter="Format" align="center">-->
      <!--              </el-table-column>-->
      <el-table-column width="180px" fixed="left">
        <template slot-scope="props">
          <el-button
            class="el-button--mini"
            type="warning"
            icon="el-icon-edit"
            @click="supplyBy(props.row)"
            >提供</el-button
          >
          <el-button
            class="el-button--mini"
            type="danger"
            icon="el-icon-edit"
            @click="consumeBy(props.row)"
            >获得</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="total"
      :page-size="searchForm.pageSize"
      :current-page="searchForm.pageNum"
      @current-change="queryByCondition"
      layout="total, prev, pager, next, jumper"
    ></el-pagination>
  </div>
</template>

<script>
// import {mapState} from 'vuex'
// import New from './components/New.vue';
import InsertPlayer from "@/components/InsertPlayer";
import GoldCoinDeal from "@/components/GoldCoinDeal";
export default {
  name: "Player",
  components: {
    GoldCoinDeal,
    InsertPlayer,
    //  New,Old,
  },
  props: {
    sampleP: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      sampleD: "value",
      // String sampleD = "value";
      primary: "danger",
      user: {
        username: "张三",
        password: "12212",
      },
      searchForm: {
        pageNum: 1,
        pageSize: 6,
        queryCondition: {
          goldCoinMax: null,
          goldCoinMin: null,
          nickNameSml: "",
          playerCodeSml: "",
          professions: [],
        },
      },
      total: 23,
      results: [],
      supplier: {},
      consumer: {},
    };
  },
  computed: {
    // professionTypes: this.$store.state.professionTypes,

    // sampleC() {
    //     return this.sampleD+'--';
    // }
    professionTypes() {
      return this.$store.state.professionTypes;
    },
    //  ...mapState(['professionTypes'])
  },
  created() {},
  mounted() {
    this.queryByCondition(1);
  },
  methods: {
    sampleM() {},
    appear() {
      // this.$message.success(JSON.stringify(this.user) + i);
      // this.$notify.warning(JSON.stringify(this.searchForm));

      this.$http({
        method: "get",
        url: "/ceto/common/professionTypes",
      }).then(
        (res) => {
          console.log(res.data);
          this.$message.success(JSON.stringify(res.data));
        },
        // function(error){
        //   console.log(error)
        // }
        (error) => {
          console.log(error);
        }
      );
    },
    queryByCondition(pageNum) {
      if (pageNum) this.searchForm.pageNum = pageNum;
      this.$http({
        method: "post",
        url: "/ceto/player/query",
        data: this.searchForm,
      }).then(
        (res) => {
          this.total = res.data.total;
          this.results = res.data.results;
        },
        (error) => {
          this.$message.warning("query mistake：" + error.response.status);
        }
      );
    },
    // MVVM
    professionFormat(row) {
      //   console.log (row.profession);
      // console.log(this.professionTypes);
      //   return 1;
      //   for (let e of this.professionTypes) {
      //      if (e.value === row.profession){
      //        return e.text;
      //      }
      //   }
      let target = this.professionTypes.find((e) => e.value === row.profession);
      return target ? target.text : "N/A";
    },

    supplyBy(row) {
      this.supplier = row;
    },

    consumeBy(row) {
      this.consumer = row;
    },
  },
  watch: {
    // sampleC(newValue, oldValue) {
    //
    // }
  },
};
</script>

<!--<style scoped>-->
<style lang="scss" scoped>
.insert-player {
}
</style>
